<script type="text/javascript">
    $(function () {
        
        getButton("backup_restore");
    });

    function ui_backup_restore_init_list(toolbar) {       
        $("#ui_backup_restore_dg").datagrid({       //初始化treegrid
            url: "ashx/bg_backup_restore.ashx?action=getall",
            striped: true, rownumbers: true, 
            idField: 'id',
            columns: [[
                { field: 'ck', checkbox: true },
                { field: 'backupfile', title: '数据库备份', width: 300 },
                { field: 'backupdate', title: '备份时间', width: 200 }
            ]],
            toolbar: toolbar.length == 0 ? null : toolbar                    
        });
    }

	function ui_backup_restore_backup(){
		
	    var para = {};
	    para.action = "backup";
	    para.timespan = new Date().getTime();

	    var ids = [];
	    var rows = $("#ui_backup_restore_dg").datagrid("getChecked");	    
	    $.ajax({
	        url: "ashx/bg_backup_restore.ashx",
	        data: para,
	        type: "POST",
	        dataType: "json",
	        success: function (data) {
	            if (data.success) {
	                $.show_warning("提示", "备份数据库操作成功！");
	                $("#ui_backup_restore_dg").datagrid("reload").datagrid('clearSelections').datagrid('clearChecked');
	            } else {
	                $.show_warning("提示", data.msg);
	            }
	        }
	    });
	}
	
	function ui_backup_restore_restore(){
	    var rows = $("#ui_backup_restore_dg").datagrid("getChecked");
	    if (rows.length < 1) {
	        $.show_warning("提示", "请先勾选要恢复的文件！");
	        return;
	    }
	    var para = {};
	    para.action = "restore";
	    para.timespan = new Date().getTime();
	    para.backupfile = rows[0].backupfile;

	    
	    
	    $.ajax({
	        url: "ashx/bg_backup_restore.ashx",
	        data: para,
	        type: "POST",
	        dataType: "json",
	        success: function (data) {
	            if (data.success) {
	                $.show_warning("提示", "恢复数据库操作成功！");
	                $("#ui_backup_restore_dg").datagrid("reload").datagrid('clearSelections').datagrid('clearChecked');
	            } else {
	                $.show_warning("提示", data.msg);
	            }
	        }
	    });
	}
</script>
<div id="ui_backup_restorelayout" class="easyui-layout" data-options="fit:true,border:false">
	<div data-options="region:'center',border:false">
        <table id="ui_backup_restore_dg" data-options="fit:true,border:false">
        </table>		
	</div>
</div>